package io.renren.modules.manage.controller;

import io.renren.modules.manage.dao.MySQLGeneratorDao;
import io.renren.modules.seller.entity.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 检索所有库表
 *
 * @author Mark 15373178086@163.com
 * @date 2020-02-21 12:05:42
 */
@Slf4j
@RestController
@RequestMapping("manage/table")
public class TableController {

    @Autowired
    private MySQLGeneratorDao mySQLGeneratorDao;

    /**
     * 返回全部列表
     *
     * @return TbBrands
     */
    @RequestMapping("/findAll")
    public List<Map<String, Object>> findAll() {
        return mySQLGeneratorDao.queryList(new HashMap<>(4));
    }

    /**
     * 查询+分页
     *
     * @return PageResult
     */
    @RequestMapping("/search")
    public PageResult search(String tableName, String page, String limit) {
        log.info("table name [{}]", tableName);
        Map<String, String> table = mySQLGeneratorDao.queryTable(tableName);
        ArrayList<Map<String, String>> list = new ArrayList<>();
        list.add(table);
        return new PageResult(1, list);
    }

    /**
     * 返回全部列表
     *
     * @return PageResult
     */
    @RequestMapping("/findPage")
    public PageResult findPage(String tableName) {
        log.info("table name [{}]", tableName);
        Map<String, String> table = mySQLGeneratorDao.queryTable(tableName);
        ArrayList<Map<String, String>> list = new ArrayList<>();
        list.add(table);
        return new PageResult(1, list);
    }

}
